

import { game } from "../../../../script/game/control/game";
import { giftType, relationType } from "../../../../script/game/gameType";
import { ListItem } from "../../../../script/util/ListView/ListItem";
import { ccs } from "../../../../script/util/services";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends ListItem<giftType> {
    
    //标题
    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Label)
    desc: cc.Label = null;

    @property(cc.Label)
    cost: cc.Label = null;

    @property(cc.Label)
    power: cc.Label = null;
    
    //收入
    @property(cc.Label)
    effect: cc.Label = null;

    start () {
        
    }
    initItem(data: giftType, index: number) {
            if(!data) return ;
            //如果条件达到，则显示
            this.title.string = data.name;
            this.desc.string = data.desc;
            this.cost.string = "¥" + ccs.gf.getOmitNum(data.cost);
            this.effect.string = "亲密度增加" + data.effect;
            this.power.string = data.power + "精力";
    }
    onItemclick(data: giftType) {
        let chat = game.playerMgr.heroInfo.relation.chat;
       let result = game.playerMgr.doSocial(chat.id, data, chat.hero.name);
       if(!result) return;
        switch(data.id){
            case "marray": 
                game.playerMgr.goMarray();
                break;
                case "makeChild":
                    game.playerMgr.makeChild();
                    break;
                    case "fenshou":
                        game.playerMgr.unLove();
                        break;
                        case "jiaowang":
                            game.playerMgr.love();
                            break;
                            case "yaoqian":
                                game.playerMgr.begMoney();
                                break;
                                case "disease":
                                    ccs.winMgr.showWin("chooseIllWin", {heroId: chat.id});
                                    break;
                                    case "xuming":
                                        game.playerMgr.bag.figureBag.getItem(chat.id).data.hero.heroInfo.lifeTime += 12
                                        break;
                                        default:
                                            break;
        }
        ccs.mainEmitter.emit("updateRelation");
        ccs.mainEmitter.emit("updateAttribute");
    }
}
